﻿using System.Collections.Generic;
using System.Xml.XPath;
using System.Configuration;
using GeoCode.Core;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MSGeoCoder.Services.Yahoo;

namespace TestGeoCode
{
    /// <summary>
    ///This is a test class for YahooWhereGeoCoderTest and is intended
    ///to contain all YahooWhereGeoCoderTest Unit Tests
    ///</summary>
    [TestClass]
    public class YahooWhereGeoCoderTest
    {
        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext { get; set; }

        #region Additional test attributes

        // 
        //You can use the following additional attributes as you write your tests:
        //
        public const string _woeid = "37149";
        public const string _appId = "lUPJNY7V34GIT8sgRLUN.gITFtVELqOWY4mROTwpNVHy2lS30pHo3GbKLEyJY7bbKg--";
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //

        #endregion

        /// <summary>
        ///A test for GeoCode
        ///</summary>
        [TestMethod]
        public void GeoCodeTest()
        {
            string appId = _appId;
            var target = new YahooWhereGeoCoder(appId); // TODO: Initialize to an appropriate value
            string street = string.Empty; // TODO: Initialize to an appropriate value
            string city = string.Empty; // TODO: Initialize to an appropriate value
            string state = string.Empty; // TODO: Initialize to an appropriate value
            string postalCode = "KT6 4SW"; // TODO: Initialize to an appropriate value
            string country = string.Empty; // TODO: Initialize to an appropriate value

            //<?xml version="1.0"?>
//<ResultSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:yahoo:maps" xsi:schemaLocation="urn:yahoo:maps http://local.yahooapis.com/MapsService/V1/GeocodeResponse.xsd"><Result precision="zip"><Latitude>51.397072</Latitude><Longitude>-0.300250</Longitude><Address></Address><City>London, Surbiton, KT6 4SW</City><State>United Kingdom</State><Zip></Zip><Country>GB</Country></Result></ResultSet>
//<!-- ws15.ydn.gq1.yahoo.com uncompressed/chunked Wed May 25 21:03:08 PDT 2011 -->
            var expected = new Address[1]; // TODO: Initialize to an appropriate value
            expected[0] = new Address {Country = "GB", State = "United Kingdom", City = "London, Surbiton, KT6 4SW"};

            Address[] actual = target.GeoCode(street, city, state, postalCode, country);

            Assert.IsNotNull(actual);
            Assert.AreEqual(expected[0].Country, actual[0].Country);
            Assert.AreEqual(expected[0].State, actual[0].State);
            Assert.AreEqual(expected[0].City, actual[0].City);

            //  Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for GeoCode
        ///</summary>
        [TestMethod]
        public void GeoCodeTest1()
        {
            string appId = _appId;
            var target = new YahooWhereGeoCoder(appId); // TODO: Initialize to an appropriate value
            string address = "UK"; // TODO: Initialize to an appropriate value
            Address[] expected = null; // TODO: Initialize to an appropriate value
            Address[] actual;
            actual = target.GeoCode(address);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }


        /// <summary>
        ///A test for Neighbors
        ///</summary>
        [TestMethod]
        public void NeighborsTest()
        {
            string appId = _appId;
                
            var target = new YahooWhereGeoCoder(appId); //  
            string WOEID = _woeid;  
            List<YahooPlace> expected = null; //  
            List<YahooPlace> actual;
            actual = target.Neighbors(WOEID);
            Assert.AreEqual(9, actual.Count);
            
        }

        /// <summary>
        ///A test for Place
        ///</summary>
        [TestMethod]
        public void PlaceTest()
        {
            string appId = _appId;
            var target = new YahooWhereGeoCoder(appId); // TODO: Initialize to an appropriate value
            string WOEID = _woeid;
            YahooPlace[] expected = null; // TODO: Initialize to an appropriate value
            YahooPlace[] actual;
            actual = target.Place(WOEID);
            Assert.AreEqual(1, actual.Length);
            
        }

        /// <summary>
        ///A test for Places
        ///</summary>
        [TestMethod]
        public void PlacesTest()
        {
            string appId = _appId;
            var target = new YahooWhereGeoCoder(appId); // TODO: Initialize to an appropriate value
            string PlaceName = "Goole"; // TODO: Initialize to an appropriate value
            string Focus = ""; // TODO: Initialize to an appropriate value
            YahooPlace[] expected = null; // TODO: Initialize to an appropriate value
            YahooPlace[] actual;
            actual = target.Places(PlaceName, Focus);
            Assert.AreEqual(1, actual.Length);
            
        }

        /// <summary>
        ///A test for Ancestors
        ///</summary>
        [TestMethod]
        public void AncestorsTest()
        {
            string appId = _appId;
            var target = new YahooWhereGeoCoder(appId); 
            string WOEID = _woeid;
            List<YahooPlace> expected = null; // TODO: Initialize to an appropriate value
            IEnumerable<YahooPlace> tmp;

            List<YahooPlace> actual;
            actual =  target.Ancestors(WOEID);
            Assert.AreEqual(4, actual.Count);
            
        }


        /// <summary>
        ///A test for BelongsTo
        ///</summary>
        [TestMethod]
        public void BelongsToTest()
        {
            string appId = _appId;
            var target = new YahooWhereGeoCoder(appId); // TODO: Initialize to an appropriate value
            string WOEID = _woeid;
            YahooPlace[] expected = null; // TODO: Initialize to an appropriate value
            YahooPlace[] actual;
            actual = target.BelongsTo(WOEID);
            Assert.AreEqual(10, actual.Length);
             
        }

        /// <summary>
        ///A test for Children
        ///</summary>
        [TestMethod]
        public void ChildrenTest()
        {
            string appId = _appId;
            var target = new YahooWhereGeoCoder(appId); // TODO: Initialize to an appropriate value

            //37149 Elmbridge Borough -->Surrey-->England-->United Kingdom
            string WOEID = _woeid;
            List<YahooPlace> expected = null; // TODO: Initialize to an appropriate value
            List<YahooPlace> actual;
            actual = target.Children(WOEID);

            Assert.AreEqual(2, actual.Count);
            Assert.AreEqual("Thames Ditton Railway Station", actual[0].Name);
            Assert.AreEqual(26787434, actual[1].Weoid);
        }

        /// <summary>
        ///A test for YahooWhereGeoCoder Constructor
        ///</summary>
        [TestMethod]
        public void YahooWhereGeoCoderConstructorTest()
        {
            string appId = _appId;
                // TODO: Initialize to an appropriate value

            var target = new YahooWhereGeoCoder(appId);
            Assert.IsNotNull(target);
            Assert.AreEqual(appId, target.AppId);
        }


        /// <summary>
        ///A test for GetPlaceFromLatLng
        ///</summary>
        [TestMethod]
        public void GetPlaceFromLatLngTest()
        {
            string lng = "1"; // TODO: Initialize to an appropriate value
            string lat = "51"; // TODO: Initialize to an appropriate value

            YahooPlace actual;
            actual = YahooWhereGeoCoder.GetPlaceFromLatLng(lng, lat);
            Assert.AreEqual(26352379, actual.Weoid);
            Assert.AreEqual("TN29 0", actual.Name);
        }

        ///// <summary>
        /////A test for GetPlaces
        /////</summary>
        //[TestMethod()]
        //public void GetPlacesTest()
        //{
        //    string WEOID = "37149"; // TODO: Initialize to an appropriate value
        //    List<YahooPlace> expected = null; // TODO: Initialize to an appropriate value
        //    List<YahooPlace> actual;

        //    //The get places method will return places which match the string
        //    //37149 Elmbridge Borough -->Surrey-->England-->United Kingdom
        //    actual = YahooWhereGeoCoder.GetPlaces(WEOID);

        //    Assert.AreEqual(4, actual.Count);
        //    Assert.AreEqual("Elmbridge Borough", actual[0].Name);
        //    Assert.AreEqual("Surrey", actual[1].Name);
        //    Assert.AreEqual("England", actual[2].Name);
        //    Assert.AreEqual("United Kingdom", actual[3].Name);
        //}


        /// <summary>
        ///A test for MapAccuracy
        ///</summary>
        [TestMethod]
        [DeploymentItem("GeoCode.dll")]
        public void MapAccuracyTest()
        {
            PrivateObject param0 = null; // TODO: Initialize to an appropriate value
            var target = new YahooWhereGeoCoder_Accessor(param0); // TODO: Initialize to an appropriate value
            string precision = string.Empty; // TODO: Initialize to an appropriate value
            var expected = new AddressAccuracy(); // TODO: Initialize to an appropriate value
            AddressAccuracy actual;
            actual = target.MapAccuracy(precision);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }


       

        /// <summary>
        ///A test for Siblings
        ///</summary>
        [TestMethod]
        public void SiblingsTest()
        {
            string appId = _appId;
            var target = new YahooWhereGeoCoder(appId); 
            string WOEID = _woeid; 
            List<YahooPlace> expected = null; // TODO: Initialize to an appropriate value
            List<YahooPlace> actual;
            actual = target.Siblings(WOEID);
            Assert.AreEqual(10, actual.Count);
            
        }


        /// <summary>
        ///A test for AppId
        ///</summary>
        [TestMethod]
        public void AppIdTest()
        {
            string appId =_appId;
            var target = new YahooWhereGeoCoder(appId); // TODO: Initialize to an appropriate value
            string actual;
            actual = target.AppId;
            Assert.AreEqual(appId,actual);
        }
    }
}